
import * as ip from 'internal-ip';
import { ApiConfig } from 'tnwx';

/**
 *  根据是否开启HMR设置不同实体类加载方式， 解决开启hmr 时，无法加载实体类问题
 */
let entities:string[] = [];
if ((module as any).hot) {
    const entityContext = require['context']('../', true, /\.entity\.ts$/);
    entities = [
        ...entityContext.keys().map(id => {
            const entityModule = entityContext(id);
            const [entity] = Object.values(entityModule);
            return entity;
        })
    ]
} else {
    entities = ["dist/**/*.entity{.ts,.js}"];
}

export default {
    host: 'http://' + ip.v4.sync(),
    port: parseInt(process.env.PORT) || 3000,
    // 是否开启swagger
    enableSwagger: true,
    // 数据库配置
    DATABASE_CONFIG: { 
        type: 'mysql',
        host: 'localhost',
        port: 3306,
        username: 'root',
        password: '',
        database: 'my_bili',
        timezone: 'UTC',
        charset: 'utf8mb4',
        keepConnectionAlive: true,
        entities: entities,
        synchronize: true,
        dateStrings: true ,// 强制日期类型(TIMESTAMP, DATETIME, DATE)以字符串返回，而不是一javascript Date对象返回. (默认: false)
        // logging: true, 
    },
    // 静态资源配置 
    ASSETS: {
        root: 'public',
        prefix: '/static' // 注意需要在开头加斜杠
    },
    // 微信相关配置数据（配合tnwx依赖包, 配置请查看文档https://javen205.gitee.io/tnwx/guide/common/init.html#%E5%88%9D%E5%A7%8B%E5%8C%96）
    WX_CONFIG: {
        myMiniApp: new ApiConfig(
            'wx8a525fd36086c7a9',
            '8ae18d6bbb8d9fec4249f4568967fa73',
        ),
        yangche: new ApiConfig(
            'wx8bc01fecc1080870',
            ''
        )
    }
    
}